<?php

/**
 * This is the model class for table "job_info".
 */
class JobInfo extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'job_info':
	 * @var integer $id
	 * @var integer $url_id
	 * @var string $company
	 * @var string $industry
	 * @var string $vocation
	 * @var integer $recruit_num
	 * @var integer $compensation
	 * @var string $work_address
	 * @var string $age
	 * @var string $sex
	 * @var string $job_descriptions
	 * @var integer $info_state
	 * @var string $linkman
	 * @var string $link_url
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return JobInfo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'job_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('url_id, company, industry, vocation, recruit_num, compensation, work_address, age, sex, job_descriptions, linkman, link_url', 'required'),
			array('url_id, recruit_num, compensation, info_state', 'numerical', 'integerOnly'=>true),
			array('company', 'length', 'max'=>50),
			array('industry, work_address, link_url', 'length', 'max'=>40),
			array('vocation', 'length', 'max'=>80),
			array('age, sex', 'length', 'max'=>10),
			array('linkman', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, url_id, company, industry, vocation, recruit_num, compensation, work_address, age, sex, job_descriptions, info_state, linkman', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'url_id' => '链接地址编号',
			'company' => '公司',
			'industry' => '行业',
			'vocation' => '职位',
			'recruit_num' => '招工人数',
			'compensation' => '薪水',
			'work_address' => '地点',
			'age' => '年龄',
			'sex' => '性别',
			'job_descriptions' => '职业简介',
			'info_state' => '状态',
			'linkman' => '联系人',
			'link_url' => '图片链接',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$data=explode('~',$this->compensation);
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('url_id',$this->url_id);

		$criteria->compare('company',$this->company,true);

		$criteria->compare('industry',$this->industry,true);

		$criteria->compare('vocation',$this->vocation,true);

		$criteria->compare('recruit_num',$this->recruit_num);

		$criteria->compare('compensation','>='.$data[0]);
		if(count($data)!=1)
		$criteria->compare('compensation','<='.$data[1]);
		$criteria->compare('work_address',$this->work_address,true);

		$criteria->compare('age',$this->age,true);

		$criteria->compare('sex',$this->sex,true);

		$criteria->compare('job_descriptions',$this->job_descriptions,true);

		$criteria->compare('info_state',$this->info_state);

		$criteria->compare('linkman',$this->linkman,true);

		$criteria->compare('link_url',$this->link_url,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	public function search1()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$data=explode('~',$this->compensation);
		$add=explode(' ',$this->work_address);
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('url_id',$this->url_id);

		$criteria->compare('company',$this->company,true);

		$criteria->compare('industry',$this->industry,true);

		$criteria->compare('vocation',$this->vocation,true);

		$criteria->compare('recruit_num',$this->recruit_num);

		$criteria->compare('compensation','>='.$data[0]);
		if(count($data)!=1)
		$criteria->compare('compensation','<='.$data[1]);
		$criteria->compare('work_address',$add[0],true);
		$criteria->compare('work_address',$add[1],true);
		$criteria->compare('age',$this->age,true);

		$criteria->compare('sex',$this->sex,true);

		$criteria->compare('job_descriptions',$this->job_descriptions,true);

		$criteria->compare('info_state',1);

		$criteria->compare('linkman',$this->linkman,true);

		$criteria->compare('link_url',$this->link_url,true);

		return $criteria;
	}
}